package com.app114.app.android.rk;

import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.app114.app.android.rk.utils.UmengUtil;

public abstract class BaseFragmentActivity extends SherlockFragmentActivity {
	public String TAG;
	public Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		TAG = this.getClass().getSimpleName();
		if (!TAG.equals("LoadActivity")) {
			getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		}
		UmengUtil.onError(this) ;
		activitySetup(savedInstanceState);
	}
	
	@Override
	protected void onResume() {
		UmengUtil.onResume(this) ;
		super.onResume();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return _onCreateOptionsMenu(menu);
	}
	
	@Override
	protected void onPause() {
		UmengUtil.onPause(this) ;
		super.onPause();
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			if (!TAG.equals(Browser.TAG)) {
				finish();
				return true;
			}
			break;

		default:
			break;
		}
		return _onOptionsItemSelected(item);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		activityDestory();
	}

	public void fullScreen() {
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
	}

	/**
	 * set up views
	 */
	protected abstract void activitySetup(Bundle savedInstanceState);

	/**
	 * 
	 * @param menu
	 * @return
	 */
	protected abstract boolean _onCreateOptionsMenu(Menu menu);

	/**
	 * 
	 * @param item
	 * @return
	 */
	protected abstract boolean _onOptionsItemSelected(MenuItem item);

	/**
	 * clear object
	 */
	protected abstract void activityDestory();
}
